/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef DEV_NCSI_HUAWEI_H
#define DEV_NCSI_HUAWEI_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

// OEM huawei command id
#define OEM_HUAWEI_CONTROLLER_INFO_PUBLIC    0x00
#define OEM_HUAWEI_CONTROLLER_INFO_NIC       0x01
#define OME_HUAWEI_BASE_CFG_NIC              0x04
#define OEM_HUAWEI_STATELESS_COMPUTE_CFG_NIC 0x05

#define OEM_HUAWEI_GET_DCBX_EXTRA_CMD 0x0

#pragma pack(1)
typedef struct oem_huawei_public_rsp {
    uint16_t response_code;
    uint16_t reason_code;
    uint32_t manufacturer_id;
    uint8_t  reserved;
    uint8_t  oem_command_id;
    uint8_t  sub_command_id;
    uint8_t  reserved_2;
} oem_huawei_public_rsp_t;

#define OEM_HUAWEI_GET_BDF          0x01
#define OEM_HUAWEI_BDF_INFO_RSP_LEN 16
typedef struct oem_huawei_bdf_info_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 reserved;
    uint8_t                 bus;
    uint8_t                 device;
    uint8_t                 function;
    uint32_t                check_sum;
} oem_huawei_bdf_info_rsp_t;

#define OEM_HUAWEI_GET_CHIP_TEMP     0x0A // chip temperature
#define OEM_HUAWEI_GET_OM_TEMP       0x0B // optical module temperature
#define OEM_HUAWEI_CHIP_TEMP_RSP_LEN 16
typedef struct oem_huawei_temperature_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint16_t                temperature;
    uint16_t                reserved;
    uint32_t                check_sum;
} oem_huawei_temperature_rsp_t;

#define OEM_HUAWEI_GET_LINK_ABILITY     0x05 // pcie interface ability
#define OEM_HUAWEI_LINK_ABILITY_RSP_LEN 16
typedef struct oem_huawei_link_ability_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 link_width;
    uint8_t                 link_speed;
    uint16_t                reserved;
    uint32_t                check_sum;
} oem_huawei_link_ability_rsp_t;

#define OEM_HUAWEI_GET_LINK_INFO     0x06 // pcie interface info
#define OEM_HUAWEI_LINK_INFO_RSP_LEN 16
typedef struct oem_huawei_link_info_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 link_width;
    uint8_t                 link_speed;
    uint16_t                reserved;
    uint32_t                check_sum;
} oem_huawei_link_info_rsp_t;

#define OEM_HUAWEI_GET_DCBX_STATUS     0x02 // dcbx status
#define NCSI_HUAWEI_DCBX_FIELD_LEN     8
#define OEM_HUAWEI_DCBX_STATUS_RSP_LEN 48
typedef struct oem_huawei_dcbx_status_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 cos2_up[NCSI_HUAWEI_DCBX_FIELD_LEN];
    uint8_t                 up_pgid[NCSI_HUAWEI_DCBX_FIELD_LEN];
    uint8_t                 pgpct[NCSI_HUAWEI_DCBX_FIELD_LEN];
    uint8_t                 strict[NCSI_HUAWEI_DCBX_FIELD_LEN];
    uint8_t                 pfcmap;
    uint8_t                 reserved[3];
    uint32_t                check_sum;
} oem_huawei_dcbx_status_rsp_t;

#define OEM_HUAWEI_GET_DEFAULT_MAC_ADDR 0x04
#define OEM_HUAWEI_GET_MAC_ADDR         0x00 // mac address
#define OEM_HUAWEI_MAC_ADDR_RSP_LEN     64
#define NCSI_HUAWEI_MAC_ADDR_COUNT      8
typedef struct oem_huawei_mac_addr_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 mac_addr_count;
    uint8_t                 reserved[3];
    uint8_t                 mac_addr[NCSI_HUAWEI_MAC_ADDR_COUNT][6];
    uint32_t                check_sum;
} oem_huawei_mac_addr_rsp_t;

#define OEM_HUAWEI_GET_FAULT_STATE_CODE     0x0C // fault state code
#define OEM_HUAWEI_FAULT_STATE_CODE_RSP_LEN 36
#define NCSI_HUAWEI_FAULT_STATE_CODE_COUNT  11
typedef struct oem_huawei_fault_state_code_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 health_state;
    uint8_t                 error_count;
    uint16_t                error_code[NCSI_HUAWEI_FAULT_STATE_CODE_COUNT];
    uint32_t                check_sum;
} oem_huawei_fault_state_code_rsp_t;

#define OEM_HUAWEI_ENABLE_LLDP_CAPABILITY         0x0E // enable lldp capability
#define OEM_HUAWEI_ENABLE_LLDP_EXTRA_CMD          0x00
#define OEM_HUAWEI_DISABLE_LLDP_EXTRA_CMD         0x01
#define OEM_HUAWEI_ENABLE_LLDP_CAPABILITY_RSP_LEN 12
typedef struct oem_huawei_enable_lldp_capability_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint32_t                check_sum;
} oem_huawei_enable_lldp_capability_rsp_t;

#define OEM_HUAWEI_GET_LLDP_CAPABILITY         0x0F // get lldp capability
#define OEM_HUAWEI_GET_LLDP_CAPABILITY_RSP_LEN 16
typedef struct oem_huawei_get_lldp_capability_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 lldp_capability;
    uint8_t                 reserved[3];
    uint32_t                check_sum;
} oem_huawei_get_lldp_capability_rsp_t;

#define OEM_HUAWEI_GET_OPTICAL_MODULE_INFO     0x0D // optical module info
#define OEM_HUAWEI_OPTICAL_MODULE_INFO_RSP_LEN 120
#define MCTP_NCSI_OPTICAL_MODULE_FIELD_LEN     16
typedef struct oem_huawei_optical_module_info_rsp {
    oem_huawei_public_rsp_t public_rsp_header;
    uint8_t                 part_number[MCTP_NCSI_OPTICAL_MODULE_FIELD_LEN];
    uint8_t                 vendor[MCTP_NCSI_OPTICAL_MODULE_FIELD_LEN];
    uint8_t                 serial_number[MCTP_NCSI_OPTICAL_MODULE_FIELD_LEN];
    uint8_t                 identifier;
    uint8_t                 type;
    uint8_t                 connector;
    uint8_t                 reserved;
    uint16_t                transceiver_distance;
    uint16_t                wave_length;
    uint16_t                working_temperature;
    uint16_t                working_voltage;
    uint16_t                working_tx_bias;
    uint16_t                working_tx_power;
    uint16_t                working_rx_power;
    uint16_t                warning_low_temp_threshold;
    uint16_t                warning_high_temp_threshold;
    uint16_t                warning_tx_power_threshold;
    uint16_t                warning_rx_power_threshold;
    uint16_t                alarm_low_temp_threshold;
    uint16_t                alarm_high_temp_threshold;
    uint16_t                alarm_tx_power_threshold;
    uint16_t                alarm_rx_power_threshold;
    uint8_t                 rx_los_state;
    uint8_t                 tx_full_state;
    uint8_t                 reserved1[24];
    uint32_t                check_sum;
} oem_huawei_optical_module_info_rsp_t;

#pragma pack()

#ifdef __cplusplus
}
#endif

#endif // DEV_NCSI_HUAWEI_H
